#!/bin/sh
#
# Starts mender service.
#
DAEMON="mender"
DAEMON_PATH="/usr/bin/mender"
PIDFILE="/var/run/${DAEMON}.pid"
DAEMON_ARGS="daemon"

start() {
	printf "Starting mender service: "
	umask 077
	start-stop-daemon -bmSqp "$PIDFILE" -x ${DAEMON_PATH} -- ${DAEMON_ARGS}
	status=$?
	[ "${status}" = 0 ] && echo "OK" || echo "FAIL"
}

stop() {
	printf "Stopping mender service: "
	start-stop-daemon -Kqp "$PIDFILE"
	status=$?
	[ "${status}" = 0 ] && echo "OK" || echo "FAIL"
}
restart() {
	stop
	start
}

case "$1" in
	start)
		start
		;;
	stop)
		stop
		;;
	restart|reload)
		restart
		;;
	*)
		echo "Usage: $0 {start|stop|reload|restart}"
		exit 1
esac

exit $?
